﻿// ===============================================================================
// StringHelpertest.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Tools.Tests
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    /// <summary>
    /// This is a test class for StringHelper class and is intended
    /// to contain all StringHelper Unit Tests
    /// </summary>
    [TestClass()]
    public class StringHelperTest
    {
        private TestContext testContextInstance;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        /// A test for MakeSingularPascalCase
        /// </summary>
        [TestMethod()]
        public void MakeSingularPascalCaseTest()
        {
            string word1 = "my_words";

            Assert.AreEqual("MyWord", StringHelper.MakeSingularPascalCase(word1));

            string word2 = "the_cities";

            Assert.AreEqual("TheCity", StringHelper.MakeSingularPascalCase(word2));

            string word3 = "my_addresses";

            Assert.AreEqual("MyAddress", StringHelper.MakeSingularPascalCase(word3));
        }        
        
        /// <summary>
        /// A test for MakeSingularPascalCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MakeSingularPascalCaseNullWordExceptionTest()
        {
            StringHelper.MakeSingularPascalCase(null);
        }

        /// <summary>
        /// A test for MakeSingularPascalCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakeSingularPascalCaseEmtpyWordExceptionTest()
        {
            StringHelper.MakeSingularPascalCase(string.Empty);
        }

        /// <summary>
        /// A test for MakeSingularPascalCase. Word cannot be composed of blanks only.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakeSingularPascalCaseBlanksOnlyWordExceptionTest()
        {
            StringHelper.MakeSingularPascalCase(" ");
        }

        /// <summary>
        ///A test for MakeSingularCamelCase
        ///</summary>
        [TestMethod()]
        public void MakeSingularCamelCaseTest()
        {
            string word1 = "my_words";

            Assert.AreEqual("myWord", StringHelper.MakeSingularCamelCase(word1));

            string word2 = "the_cities";

            Assert.AreEqual("theCity", StringHelper.MakeSingularCamelCase(word2));

            string word3 = "my_addresses";

            Assert.AreEqual("myAddress", StringHelper.MakeSingularCamelCase(word3));
        }

        /// <summary>
        /// A test for MakeSingularCamelCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MakeSingularCamelCaseNullWordExceptionTest()
        {
            StringHelper.MakeSingularCamelCase(null);
        }

        /// <summary>
        /// A test for MakeSingularCamelCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakeSingularCamelCaseEmtpyWordExceptionTest()
        {
            StringHelper.MakeSingularCamelCase(string.Empty);
        }

        /// <summary>
        /// A test for MakeSingularCamelCase. Word cannot be composed of blanks only.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakeSingularCamelCaseBlanksOnlyWordExceptionTest()
        {
            StringHelper.MakeSingularCamelCase(" ");
        }

        /// <summary>
        /// A test for MakePluralPascalCase. 
        /// </summary>
        [TestMethod()]
        public void MakePluralPascalCaseTest()
        {
            string word1 = "my_word";

            Assert.AreEqual("MyWords", StringHelper.MakePluralPascalCase(word1));

            string word2 = "the_city";

            Assert.AreEqual("TheCities", StringHelper.MakePluralPascalCase(word2));

            string word3 = "my_address";

            Assert.AreEqual("MyAddresses", StringHelper.MakePluralPascalCase(word3));
        }

        /// <summary>
        /// A test for MakePluralPascalCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MakePluralPascalCaseNullWordExceptionTest()
        {
            StringHelper.MakePluralPascalCase(null);
        }

        /// <summary>
        /// A test for MakePluralPascalCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakePluralPascalCaseEmtpyWordExceptionTest()
        {
            StringHelper.MakePluralPascalCase(string.Empty);
        }        
        
        /// <summary>
        /// A test for MakePluralPascalCase. Word cannot be composed of blanks only.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakePluralPascalCaseBlanksOnlyWordExceptionTest()
        {
            StringHelper.MakePluralPascalCase(" ");
        }

        /// <summary>
        ///A test for MakePluralCamelCase
        ///</summary>
        [TestMethod()]
        public void MakePluralCamelCaseTest()
        {
            string word1 = "my_word";

            Assert.AreEqual("myWords", StringHelper.MakePluralCamelCase(word1));

            string word2 = "the_city";

            Assert.AreEqual("theCities", StringHelper.MakePluralCamelCase(word2));

            string word3 = "my_address";

            Assert.AreEqual("myAddresses", StringHelper.MakePluralCamelCase(word3));
        }

        /// <summary>
        /// A test for MakePluralCamelCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void MakePluralCamelCaseNullWordExceptionTest()
        {
            StringHelper.MakePluralCamelCase(null);
        }

        /// <summary>
        /// A test for MakePluralCamelCase. Word cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakePluralCamelCaseEmtpyWordExceptionTest()
        {
            StringHelper.MakePluralCamelCase(string.Empty);
        }

        /// <summary>
        /// A test for MakePluralCamelCase. Word cannot be composed of blanks only.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MakePluralCamelCaseBlanksOnlyWordExceptionTest()
        {
            StringHelper.MakePluralCamelCase(" ");
        }

        /// <summary>
        /// A test for IsEmptyOrBlanksOnly
        /// </summary>
        [TestMethod()]
        public void IsEmptyOrBlanksOnlyTest()
        {
            Assert.IsTrue(StringHelper.IsEmptyOrBlanksOnly(null), "Method doesnt returns true for null string.");
            Assert.IsTrue(StringHelper.IsEmptyOrBlanksOnly(string.Empty), "Method doesnt returns true for empty string.");
            Assert.IsTrue(StringHelper.IsEmptyOrBlanksOnly("  "), "Method doesnt returns true for string with only blanks.");

            Assert.IsFalse(StringHelper.IsEmptyOrBlanksOnly("Foo"), "Method returns true for string with length greater than 0 who has no blanks.");
        }

        /// <summary>
        ///A test for Cut
        ///</summary>
        [TestMethod()]
        public void CutTest()
        {
            string stringToTrim = "123456789";

            Assert.AreEqual(stringToTrim, stringToTrim.Cut(9, "..."));
            Assert.AreEqual("12345678...", stringToTrim.Cut(8, "..."));
        }

        /// <summary>
        ///A test for Cut
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CutNullStringExceptionTest()
        {
            StringHelper.Cut(null, 0, null);
        }
    }
}
